package com.wd.live.model.tool

import android.content.Context
import com.wd.live.model.bean.LocalData
import com.wd.live.model.bean.MeBean
import com.wd.live.model.bean.ZhiBoListBean

/**
 * 作者：马海钊
 * 时间：2023/8/16 10:23
 * 功能：
 */
class LoginHelper {
    companion object {
        @JvmStatic
        fun saveWXLoginCode(context: Context, code: String) {
            val sp = context.getSharedPreferences("login_info", Context.MODE_PRIVATE)
            sp.edit().putString("wx_code", code).commit()
        }

        fun getWxLoginCode(context: Context): String? {
            val sp = context.getSharedPreferences("login_info", Context.MODE_PRIVATE)
            return sp.getString("wx_code", null)
        }

        //存个人信息
        fun setPersonData(context: Context, bean: LocalData.UserInfo) {
            val sp = context.getSharedPreferences("login_info", Context.MODE_PRIVATE)
            sp.edit().putString("nickName", bean.nickName).apply()
            sp.edit().putString("personImg", bean.headPic).apply()
        }

        //取个人信息
        fun getPersonData(context: Context): MeBean? {
            val sp = context.getSharedPreferences("login_info", Context.MODE_PRIVATE)
            val string = sp.getString("nickName", null)
            val string1 = sp.getString("personImg", null)
            string?.let {
                if (string1 != null) {
                    val meBean = MeBean(it, string1)
                    return meBean
                }
            }
            return null
        }
    }
}
